<?php
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/1 16:45
 * Desc:
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\BaseAdminController;
use App\Lib\Logger;
use App\Models\Admin\Setting;
use App\Service\SettingService;
use App\Service\UpLoad;
use Illuminate\Http\Request;

class SetController extends BaseAdminController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $data = (new SettingService("Admin.Setting"))->first(["name"=>"site"]);
        $error = empty($data)?80000:0;
        return view("admin.setting.baisc_index", ["error"=>$error,"set"=>$data]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        $params = $request->all();
        unset($params["_token"]);
        $result = (new Setting())->new_setting($params);
        if (!empty($result) || !$result->isEmpty() || $result) {
            $this->log(Logger::LOG_LEVEL_INFO,'set','store','配置成功',$result);
            return $this->success("", "配置成功");
        }
        $this->log(Logger::LOG_LEVEL_ERROR,'set','store','配置失败',$params);
        return $this->error(80000, "配置失败");

    }


    /**
     * 上传图片
     */
    public function upload(Request $request) {
        $file = $request->file('img');
        return uploadImg($file,$request->post("path"));
    }

    /**
     * 顶部导航
     */
    public function navigationIndex() {
        return view("admin.setting.top_menu_index");
    }


    /**
     * 用户设置
     */
    public function userIndex() {
        $data = (new SettingService("Admin.Setting"))->first(["name"=>"auth"]);
        $error = empty($data)?80000:0;
        return view("admin.setting.user_index",["error"=>$error,"set"=>$data]);
    }


    /**
     * 微信设置
     */
    public function wechatIndex() {
        $data = (new SettingService("Admin.Setting"))->first(["name"=>"wechat"]);
        $error = empty($data)?80000:0;
        return view("admin.setting.wechat_index",["error"=>$error,"set"=>$data]);
    }

    /**
     * 企业微信设置
     */
    public function companyWechatIndex() {
        $data = (new SettingService("Admin.Setting"))->first(["name"=>"companyWechat"]);
        $error = empty($data)?80000:0;
        return view("admin.setting.company_wechat_index",["error"=>$error,"set"=>$data]);
    }

    /**
     * 钉钉设置
     */
    public function dingTalkIndex() {
        $data = (new SettingService("Admin.Setting"))->first(["name"=>"dingtalk"]);
        $error = empty($data)?80000:0;
        return view("admin.setting.dingtalk_index",["error"=>$error,"set"=>$data]);
    }
}
